#include <iostream>
#include <fstream>
#include <exception>
#include "LoaderXML.h"

bool            LoaderXML::loadFile(const char *path)
{
  if (this->_flux.is_open())
    this->_flux.close();
  this->_flux.open(path);
  if (this->_flux.good()
      && this->_flux.is_open())
    return true;
  return false;
}

bool    LoaderXML::loadStdin()
{
  if (this->_flux.is_open())
    this->_flux.close();
  this->_flux.open("/dev/stdin");
  if (this->_flux.good()
      && this->_flux.is_open())
    return true;
  return false;
}

std::string     LoaderXML::nextString()
{
  int                   i = 0;
  char                  c = 0;
  char                  str[512] = {0};
  std::string           tmp = "";
  std::exception        excep;

  if (!this->_flux.is_open()
      || this->_flux.bad())
     throw excep;
  while (i < 512 - 1 && !this->_flux.eof())
    {
     c = this->_flux.get();
     if (this->_flux.good())
        str[i] = c;
      else
        break;
      ++i;
    }
  tmp = str;
  return tmp;
}
